package com.kezesong.leasing.service.impl;

import com.kezesong.leasing.entity.GoodsColorEntity;
import com.kezesong.leasing.entity.GoodsLogisticsEntity;
import com.kezesong.leasing.mapper.GoodsLogisticsMapper;
import com.kezesong.leasing.service.GoodsLogisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@Service
public class GoodsLogisticsServiceImpl implements GoodsLogisticsService {

    @Autowired
    private GoodsLogisticsMapper goodsLogisticsMapper;

    @Override
    public List<GoodsLogisticsEntity> getGoodsLogistics() {
        return goodsLogisticsMapper.selectAll();
    }

    @Override
    public GoodsLogisticsEntity getGoodsLogistics(int goodsId) {
        Example example = new Example(GoodsColorEntity.class);
        example.createCriteria().andEqualTo("goodsId",goodsId);
        GoodsLogisticsEntity goodsLogisticsEntity = goodsLogisticsMapper.selectOneByExample(example);
        return goodsLogisticsEntity;
    }

    @Override
    public int addGoodsLogistics(GoodsLogisticsEntity goodsLogisticsEntity) {
        int rows = goodsLogisticsMapper.insert(goodsLogisticsEntity);
        return rows;
    }

    @Override
    public int deleteGoodsLogistics(int goodsId) {
        Example example = new Example(GoodsColorEntity.class);
        example.createCriteria().andEqualTo("goodsId",goodsId);
        int rows = goodsLogisticsMapper.deleteByExample(example);
        return rows;
    }

    @Override
    public int modifyGoodsLogistics(GoodsLogisticsEntity goodsLogisticsEntity) {
        int rows = goodsLogisticsMapper.updateByPrimaryKey(goodsLogisticsEntity);
        return rows;
    }
}
